package cate.game.server.cli.mock;

import cate.game.ManyGame;
import cate.game.role.login.msg.LoginStartResp;
import cate.game.role.login.msg.RoleCreateResp;
import cate.game.server.cli.mock.msg.MockRoleCreateReq;
import cp.solution.business.game.conf.dto.GameSrvConnectTarget;
import cp.solution.business.sys.account.dto.AccountLoginReq;
import cp.solution.business.sys.account.dto.AccountLoginResp;
import cp.solution.define.ClientType;
import cp.solution.define.PlatformType;
import cp.solution.define.SexType;
import cp.solution.manage.PrimaryClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MockCli {

    private ManyGame games;
    @Autowired
    public void setGames(ManyGame v) {
        this.games = v;
    }

    private PrimaryClient pc() {
        return this.games.api.pc();
    }

    public MockNetty netty = new MockNetty(this);

    public String token;
    public String roleId;

    public void auto() {
        try {
            AccountLoginReq req = new AccountLoginReq();
            req.setPlatformType(PlatformType.DEV.value);
            req.setUsername("admin");
            req.setPassword("321");
            req.setGameId("yd123");
            req.setChannelCode("xiaomi");
            req.setDeviceCode("device-123998");
            req.setClientType(ClientType.IOS.value);

            AccountLoginResp resp = login(req);
            log.info("登录返回:{}", resp);
            this.token = resp.getToken();
            this.roleId = "6105143288cebd51b5105247";

            GameSrvConnectTarget connectTarget = pc().login.gameSrv.getConnectTarget(1);
            log.info("连接游戏服目标：{}", connectTarget);

            netty.play();
        } catch (Exception e) {
            log.info("", e);
        }
    }

    public AccountLoginResp login(AccountLoginReq req) {
        AccountLoginResp resp = pc().login.account.login(req);
        return resp;
    }

    public void onLoginStartResp(LoginStartResp resp) {
        log.info("服务端返回了login-start {}", resp);
        MockRoleCreateReq rcr = new MockRoleCreateReq();
        rcr.name = "水电费";
        rcr.sex = SexType.FEMALE.value;
        //netty.sendNow(rcr);
    }

    public void onRoleCreateResp(RoleCreateResp resp) {
        log.info("服务端返回了role-create {}", resp);
    }
}
